def yield_average():
    length = 0
    total = 0
    while True:
        try:
            result = yield total / length
        except ZeroDivisionError:
            result = yield 0
        total += result
        length += 1

my_avg = yield_average()
next(my_avg)
print(my_avg.send(2))
print(my_avg.send(3))